﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;


namespace UI
{
    public enum RushStarRewardItemType {
        _3,
        _6,
        _9,
    }
    public class RushStarRewardItem : MonoBehaviour
    {
        public UISprite littleIcon;
        public UILabel starLabel;

        public UIGrid grid;
        public GameObject itemPrefab;


        public const string firstSmallIconSpriteName = "UI_item_title_xing_zi";
        public const string secondSmallIconSpriteName = "UI_item_title_xing_blue";
        public const string lastSmallIconSpriteName = "UI_item_title_xing_green";

        List<GameObject> itemList = new List<GameObject>();

        public void Init(List<ProtoBuf.Message.BaseResource> items, RushStarRewardItemType t) {
            foreach (var item in items) {
                var obj = GameObject.Instantiate(itemPrefab) as GameObject;
                obj.GetComponent<CommonIcon>().SetData(item.id, false, item.num);
                obj.transform.SetParent(grid.transform);
                obj.transform.localPosition = Vector3.zero;
                obj.transform.localEulerAngles = Vector3.zero;
                obj.transform.localScale = Vector3.one;
                itemList.Add(obj);
            }
            switch (t) {
                case RushStarRewardItemType._3:
                    starLabel.text = (3).ToString();
                    littleIcon.spriteName = firstSmallIconSpriteName;
                    break;
                case RushStarRewardItemType._6:
                    starLabel.text = (6).ToString();
                    littleIcon.spriteName = secondSmallIconSpriteName;
                    break;
                case RushStarRewardItemType._9:
                    starLabel.text = (9).ToString();
                    littleIcon.spriteName = lastSmallIconSpriteName;
                    break;
            }
            grid.repositionNow = true;
            grid.onReposition += () => {
                grid.transform.localPosition = Vector3.zero;
            };
        }

    }

}